<%= header %>
<%= boomerangScript %> <!-- load bomerang sync so that we can check if AutoXHR is avail -->
<script src="33-xhr-filters-custom-context.js" type="text/javascript"></script>

<script type="text/javascript">
var AppManager = function() {
	this.regex = /img\.jpg$/g;
};

AppManager.prototype.checkUrl = function(url) {
	if (url && typeof url === "string") {
		result = url.match(this.regex);
		if (result && result.length > 0) {
			return true;
		}
	}
	return false;
};

AppManager.prototype.filter = function(anchor) {
	var url = anchor.href, result;
	return this.checkUrl(url);
};

var manager = new AppManager();

</script>

<script>
BOOMR_test.init({
	instrument_xhr: true,
	AutoXHR: {
		alwaysSendXhr: true,
		excludeFilters: [{
			cb: manager.filter,
			ctx: manager,
			name: "33-xhr-filters-custom-context"
		}]
	},
	testAfterOnBeacon: BOOMR.plugins.AutoXHR ? 2 : 1,
	afterFirstBeacon: function() {
		if (!BOOMR.plugins.AutoXHR) {
			return;
		}
		setTimeout(function() {
			var xhr1 = new XMLHttpRequest();
			xhr1.addEventListener("load", function() {
				var xhr2 = new XMLHttpRequest();
				xhr2.open("GET", "/pages/07-autoxhr/support/script200.js");
				xhr2.send(null);
			});
			xhr1.open("GET", "/pages/07-autoxhr/support/img.jpg");
			xhr1.send(null);
		}, 100);
	}
});
</script>
